from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-10 14:05:44.533100
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 10, May, 2021
Time: 14:05:49
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.1280
Nobs: 287.000 HQIC: -48.8156
Log likelihood: 3495.92 FPE: 3.98128e-22
AIC: -49.2755 Det(Omega_mle): 2.92517e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.380693 0.115007 3.310 0.001
L1.Burgenland 0.073384 0.058891 1.246 0.213
L1.Kärnten -0.225667 0.052429 -4.304 0.000
L1.Niederösterreich 0.107783 0.125563 0.858 0.391
L1.Oberösterreich 0.218588 0.122340 1.787 0.074
L1.Salzburg 0.279075 0.067140 4.157 0.000
L1.Steiermark 0.108454 0.085888 1.263 0.207
L1.Tirol 0.123408 0.059423 2.077 0.038
L1.Vorarlberg -0.031453 0.054682 -0.575 0.565
L1.Wien -0.026750 0.109273 -0.245 0.807
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.412325 0.132497 3.112 0.002
L1.Burgenland 0.005107 0.067847 0.075 0.940
L1.Kärnten 0.327819 0.060403 5.427 0.000
L1.Niederösterreich 0.119309 0.144658 0.825 0.410
L1.Oberösterreich -0.069538 0.140944 -0.493 0.622
L1.Salzburg 0.230950 0.077350 2.986 0.003
L1.Steiermark 0.089119 0.098949 0.901 0.368
L1.Tirol 0.139280 0.068460 2.034 0.042
L1.Vorarlberg 0.152128 0.062997 2.415 0.016
L1.Wien -0.398030 0.125890 -3.162 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.258057 0.058639 4.401 0.000
L1.Burgenland 0.105522 0.030027 3.514 0.000
L1.Kärnten -0.012908 0.026732 -0.483 0.629
L1.Niederösterreich 0.087349 0.064021 1.364 0.172
L1.Oberösterreich 0.283031 0.062378 4.537 0.000
L1.Salzburg 0.019747 0.034233 0.577 0.564
L1.Steiermark 0.000481 0.043792 0.011 0.991
L1.Tirol 0.066863 0.030298 2.207 0.027
L1.Vorarlberg 0.077031 0.027881 2.763 0.006
L1.Wien 0.116732 0.055715 2.095 0.036
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.203066 0.055698 3.646 0.000
L1.Burgenland 0.028615 0.028521 1.003 0.316
L1.Kärnten 0.008990 0.025392 0.354 0.723
L1.Niederösterreich 0.056800 0.060810 0.934 0.350
L1.Oberösterreich 0.393615 0.059249 6.643 0.000
L1.Salzburg 0.082615 0.032516 2.541 0.011
L1.Steiermark 0.131123 0.041595 3.152 0.002
L1.Tirol 0.052150 0.028779 1.812 0.070
L1.Vorarlberg 0.081612 0.026482 3.082 0.002
L1.Wien -0.039514 0.052921 -0.747 0.455
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.433302 0.109621 3.953 0.000
L1.Burgenland 0.103947 0.056133 1.852 0.064
L1.Kärnten 0.009924 0.049974 0.199 0.843
L1.Niederösterreich 0.035538 0.119683 0.297 0.767
L1.Oberösterreich 0.116075 0.116610 0.995 0.320
L1.Salzburg 0.060975 0.063995 0.953 0.341
L1.Steiermark 0.063343 0.081865 0.774 0.439
L1.Tirol 0.199961 0.056640 3.530 0.000
L1.Vorarlberg 0.038230 0.052121 0.733 0.463
L1.Wien -0.056480 0.104155 -0.542 0.588
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.221144 0.085916 2.574 0.010
L1.Burgenland -0.012859 0.043995 -0.292 0.770
L1.Kärnten -0.005908 0.039167 -0.151 0.880
L1.Niederösterreich -0.010829 0.093802 -0.115 0.908
L1.Oberösterreich 0.414505 0.091394 4.535 0.000
L1.Salzburg 0.011476 0.050157 0.229 0.819
L1.Steiermark -0.029104 0.064162 -0.454 0.650
L1.Tirol 0.160823 0.044392 3.623 0.000
L1.Vorarlberg 0.057964 0.040850 1.419 0.156
L1.Wien 0.198904 0.081632 2.437 0.015
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.182702 0.105147 1.738 0.082
L1.Burgenland 0.024782 0.053842 0.460 0.645
L1.Kärnten -0.071136 0.047935 -1.484 0.138
L1.Niederösterreich -0.041007 0.114798 -0.357 0.721
L1.Oberösterreich 0.011285 0.111851 0.101 0.920
L1.Salzburg 0.089188 0.061384 1.453 0.146
L1.Steiermark 0.318058 0.078524 4.050 0.000
L1.Tirol 0.459701 0.054329 8.461 0.000
L1.Vorarlberg 0.148452 0.049994 2.969 0.003
L1.Wien -0.120415 0.099904 -1.205 0.228
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.203620 0.124565 1.635 0.102
L1.Burgenland 0.041232 0.063786 0.646 0.518
L1.Kärnten -0.074618 0.056787 -1.314 0.189
L1.Niederösterreich 0.110513 0.135999 0.813 0.416
L1.Oberösterreich 0.014300 0.132507 0.108 0.914
L1.Salzburg 0.194429 0.072720 2.674 0.008
L1.Steiermark 0.131840 0.093025 1.417 0.156
L1.Tirol 0.056316 0.064362 0.875 0.382
L1.Vorarlberg 0.106986 0.059226 1.806 0.071
L1.Wien 0.223194 0.118354 1.886 0.059
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.490025 0.069604 7.040 0.000
L1.Burgenland -0.012170 0.035642 -0.341 0.733
L1.Kärnten -0.017689 0.031731 -0.557 0.577
L1.Niederösterreich 0.112381 0.075993 1.479 0.139
L1.Oberösterreich 0.303364 0.074042 4.097 0.000
L1.Salzburg 0.024248 0.040634 0.597 0.551
L1.Steiermark -0.047357 0.051980 -0.911 0.362
L1.Tirol 0.082139 0.035964 2.284 0.022
L1.Vorarlberg 0.103978 0.033094 3.142 0.002
L1.Wien -0.036687 0.066134 -0.555 0.579
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.163572 0.088532 0.170864 0.222980 0.076441 0.092812 0.001088 0.168329
Kärnten 0.163572 1.000000 0.053142 0.213492 0.186760 -0.067481 0.179339 0.021531 0.308941
Niederösterreich 0.088532 0.053142 1.000000 0.239653 0.095375 0.315081 0.146685 0.025696 0.313400
Oberösterreich 0.170864 0.213492 0.239653 1.000000 0.301047 0.259822 0.104577 0.061490 0.144419
Salzburg 0.222980 0.186760 0.095375 0.301047 1.000000 0.148776 0.077046 0.090317 0.032909
Steiermark 0.076441 -0.067481 0.315081 0.259822 0.148776 1.000000 0.092918 0.100041 -0.101096
Tirol 0.092812 0.179339 0.146685 0.104577 0.077046 0.092918 1.000000 0.152070 0.164835
Vorarlberg 0.001088 0.021531 0.025696 0.061490 0.090317 0.100041 0.152070 1.000000 -0.010531
Wien 0.168329 0.308941 0.313400 0.144419 0.032909 -0.101096 0.164835 -0.010531 1.000000